﻿using System;
using UnityEngine;
using UnityEngine.Networking;

[RequireComponent(typeof(Look))]
public class AILook : AIBehaviour
{
    private Vector3 lastPos;

    public override void OnDeserialize(NetworkReader reader, bool initialState)
    {
        base.OnDeserialize(reader, initialState);
    }

    public override bool OnSerialize(NetworkWriter writer, bool forceAll)
    {
        bool flag;
        bool flag2 = base.OnSerialize(writer, forceAll);
        return (flag | flag2);
    }

    protected override void Start()
    {
        base.Start();
        this.lastPos = base.position;
    }

    private void UNetVersion()
    {
    }

    private void Update()
    {
        if (!base.isMonster || !base.isWeaponCoolingDown)
        {
            if ((base.detectedTarget != null) && (Vector3.Distance(base.position, base.detectedTarget.transform.position) < base.attackRange))
            {
                this.direction = base.detectedTarget.transform.position - base.position;
            }
            else if (base.move != null)
            {
                this.direction = base.move.direction;
            }
            else if (base.position != this.lastPos)
            {
                Vector3 vector = base.position - this.lastPos;
                if (vector.magnitude > 0f)
                {
                    this.direction = vector.normalized;
                }
                this.lastPos = base.position;
            }
        }
    }

    public Vector3 direction
    {
        get
        {
            return base.look.direction;
        }
        set
        {
            base.look.direction = value;
        }
    }
}

